<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: array template object</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
  $(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="aslogo_small.png"/></td>
  <td id="projectalign">
   <div id="projectname">AngelScript
   </div>
  </td>
    <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <span id="MSearchSelect"                onmouseover="return searchBox.OnSearchSelectShow()"                onmouseout="return searchBox.OnSearchSelectHide()">&#160;</span>
          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('doc_addon_array.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div><div class="header">
  <div class="headertitle"><div class="title">array template object </div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/scriptarray/</p>
<p>The <code>array</code> type is a <a class="el" href="doc_adv_template.html">template object</a> that allow the scripts to declare arrays of any type. Since it is a generic class it is not the most performatic due to the need to determine characteristics at runtime. For that reason it is recommended that the application registers a <a class="el" href="doc_adv_template.html#doc_adv_template_2">template specialization</a> for the array types that are most commonly used.</p>
<p>The type is registered with <code>RegisterScriptArray(asIScriptEngine *engine, bool defaultArrayType)</code>. The second parameter should be set to true if you wish to allow the syntax form <code>type[]</code> to declare arrays.</p>
<p>Compile the add-on with the pre-processor define AS_USE_STLNAMES=1 to register the methods with the same names as used by C++ STL where the methods have the same significance. Not all methods from STL is implemented in the add-on, but many of the most frequent once are so a port from script to C++ and vice versa might be easier if STL names are used.</p>
<p>Compile the add-on with the pre-processor define AS_USE_ACCESSORS=1 to register length as a virtual property instead of the method length().</p>
<p>Compile the add-on with the pre-processor define AS_NO_IMPL_OPS_WITH_STRING_AND_PRIMITIVE=1 to disable the implicit operations with primitives that automatically formats the primitive values to strings.</p>
<h1><a class="anchor" id="doc_addon_array_1"></a>
Public C++ interface</h1>
<div class="fragment"><div class="line"><span class="keyword">class </span>CScriptArray</div>
<div class="line">{</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line">  <span class="comment">// Set the memory functions that should be used by all CScriptArrays</span></div>
<div class="line">  <span class="keyword">static</span> <span class="keywordtype">void</span> SetMemoryFunctions(<a class="code hl_typedef" href="angelscript_8h.html#abfe11f5787462216b1682a5d3f5486be">asALLOCFUNC_t</a> allocFunc, <a class="code hl_typedef" href="angelscript_8h.html#adeecc934971e695fc4441a47694860fb">asFREEFUNC_t</a> freeFunc);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Factory functions</span></div>
<div class="line">  <span class="keyword">static</span> CScriptArray *Create(<a class="code hl_class" href="classas_i_type_info.html">asITypeInfo</a> *arrayType);</div>
<div class="line">  <span class="keyword">static</span> CScriptArray *Create(<a class="code hl_class" href="classas_i_type_info.html">asITypeInfo</a> *arrayType, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> length);</div>
<div class="line">  <span class="keyword">static</span> CScriptArray *Create(<a class="code hl_class" href="classas_i_type_info.html">asITypeInfo</a> *arrayType, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> length, <span class="keywordtype">void</span> *defaultValue);</div>
<div class="line">  <span class="keyword">static</span> CScriptArray *Create(<a class="code hl_class" href="classas_i_type_info.html">asITypeInfo</a> *arrayType, <span class="keywordtype">void</span> *listBuffer);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Memory management</span></div>
<div class="line">  <span class="keywordtype">void</span> AddRef() <span class="keyword">const</span>;</div>
<div class="line">  <span class="keywordtype">void</span> Release() <span class="keyword">const</span>;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Type information</span></div>
<div class="line">  <a class="code hl_class" href="classas_i_type_info.html">asITypeInfo</a>   *GetArrayObjectType() <span class="keyword">const</span>;</div>
<div class="line">  <span class="keywordtype">int</span>            GetArrayTypeId() <span class="keyword">const</span>;</div>
<div class="line">  <span class="keywordtype">int</span>            GetElementTypeId() <span class="keyword">const</span>;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Get the current size</span></div>
<div class="line">  <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> GetSize() <span class="keyword">const</span>;</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// Returns true if the array is empty</span></div>
<div class="line">  <span class="keywordtype">bool</span> IsEmpty() <span class="keyword">const</span>;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Pre-allocates memory for elements</span></div>
<div class="line">  <span class="keywordtype">void</span> Reserve(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> numElements);</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// Resize the array</span></div>
<div class="line">  <span class="keywordtype">void</span> Resize(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> numElements);</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// Get a pointer to an element. Returns 0 if out of bounds</span></div>
<div class="line">  <span class="keywordtype">void</span>       *At(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> index);</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">void</span> *At(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> index) <span class="keyword">const</span>;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Set value of an element. </span></div>
<div class="line">  <span class="comment">// The value arg should be a pointer to the value that will be copied to the element.</span></div>
<div class="line">  <span class="comment">// Remember, if the array holds handles the value parameter should be the </span></div>
<div class="line">  <span class="comment">// address of the handle. The refCount of the object will also be incremented</span></div>
<div class="line">  <span class="keywordtype">void</span>  SetValue(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> index, <span class="keywordtype">void</span> *value);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Copy the contents of one array to another (only if the types are the same)</span></div>
<div class="line">  CScriptArray &amp;operator=(<span class="keyword">const</span> CScriptArray&amp;);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Compare two arrays</span></div>
<div class="line">  <span class="keywordtype">bool</span> operator==(<span class="keyword">const</span> CScriptArray &amp;) <span class="keyword">const</span>;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Array manipulation</span></div>
<div class="line">  <span class="keywordtype">void</span> InsertAt(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> index, <span class="keywordtype">void</span> *value);</div>
<div class="line">  <span class="keywordtype">void</span> RemoveAt(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> index);</div>
<div class="line">  <span class="keywordtype">void</span> InsertLast(<span class="keywordtype">void</span> *value);</div>
<div class="line">  <span class="keywordtype">void</span> RemoveLast();</div>
<div class="line">  <span class="keywordtype">void</span> SortAsc();</div>
<div class="line">  <span class="keywordtype">void</span> SortAsc(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> startAt, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> count);</div>
<div class="line">  <span class="keywordtype">void</span> SortDesc();</div>
<div class="line">  <span class="keywordtype">void</span> SortDesc(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> startAt, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> count);</div>
<div class="line">  <span class="keywordtype">void</span> Sort(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> startAt, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> count, <span class="keywordtype">bool</span> asc);</div>
<div class="line">  <span class="keywordtype">void</span> Sort(<a class="code hl_class" href="classas_i_script_function.html">asIScriptFunction</a> *less, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> startAt, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> count);</div>
<div class="line">  <span class="keywordtype">void</span> Reverse();</div>
<div class="line">  <span class="keywordtype">int</span>  Find(<span class="keywordtype">void</span> *value) <span class="keyword">const</span>;</div>
<div class="line">  <span class="keywordtype">int</span>  Find(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> startAt, <span class="keywordtype">void</span> *value) <span class="keyword">const</span>;</div>
<div class="line">  <span class="keywordtype">int</span>  FindByRef(<span class="keywordtype">void</span> *ref) <span class="keyword">const</span>;</div>
<div class="line">  <span class="keywordtype">int</span>  FindByRef(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> startAt, <span class="keywordtype">void</span> *ref) <span class="keyword">const</span>;</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// Returns the address of the inner buffer for direct manipulation</span></div>
<div class="line">  <span class="keywordtype">void</span> *GetBuffer();</div>
<div class="line">};</div>
<div class="ttc" id="aangelscript_8h_html_abfe11f5787462216b1682a5d3f5486be"><div class="ttname"><a href="angelscript_8h.html#abfe11f5787462216b1682a5d3f5486be">asALLOCFUNC_t</a></div><div class="ttdeci">void *(* asALLOCFUNC_t)(size_t)</div><div class="ttdoc">The function signature for the custom memory allocation function.</div><div class="ttdef"><b>Definition:</b> angelscript.h:645</div></div>
<div class="ttc" id="aangelscript_8h_html_ac8186f029686800b7ce36bde4a55c815"><div class="ttname"><a href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a></div><div class="ttdeci">unsigned int asUINT</div><div class="ttdoc">32 bit unsigned integer</div><div class="ttdef"><b>Definition:</b> angelscript.h:610</div></div>
<div class="ttc" id="aangelscript_8h_html_adeecc934971e695fc4441a47694860fb"><div class="ttname"><a href="angelscript_8h.html#adeecc934971e695fc4441a47694860fb">asFREEFUNC_t</a></div><div class="ttdeci">void(* asFREEFUNC_t)(void *)</div><div class="ttdoc">The function signature for the custom memory deallocation function.</div><div class="ttdef"><b>Definition:</b> angelscript.h:647</div></div>
<div class="ttc" id="aclassas_i_script_function_html"><div class="ttname"><a href="classas_i_script_function.html">asIScriptFunction</a></div><div class="ttdoc">The interface for a script function description.</div><div class="ttdef"><b>Definition:</b> angelscript.h:4000</div></div>
<div class="ttc" id="aclassas_i_type_info_html"><div class="ttname"><a href="classas_i_type_info.html">asITypeInfo</a></div><div class="ttdoc">The interface for describing types This interface is used to describe the types in the script engine.</div><div class="ttdef"><b>Definition:</b> angelscript.h:3704</div></div>
</div><!-- fragment --><h1><a class="anchor" id="doc_addon_array_2"></a>
Public script interface</h1>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="doc_datatypes_arrays.html">Arrays in the script language</a></dd></dl>
<h1><a class="anchor" id="doc_addon_array_4"></a>
C++ example</h1>
<p>This function shows how a script array can be instantiated from the application and then passed to the script.</p>
<div class="fragment"><div class="line"><span class="comment">// Registered with AngelScript as &#39;array&lt;string&gt; @CreateArrayOfString()&#39;</span></div>
<div class="line">CScriptArray *CreateArrayOfStrings()</div>
<div class="line">{</div>
<div class="line">  <span class="comment">// If called from the script, there will always be an active </span></div>
<div class="line">  <span class="comment">// context, which can be used to obtain a pointer to the engine.</span></div>
<div class="line">  <a class="code hl_class" href="classas_i_script_context.html">asIScriptContext</a> *ctx = <a class="code hl_function" href="group__api__principal__functions.html#gaf8b78824db10b0f757990805a4e18f70">asGetActiveContext</a>();</div>
<div class="line">  <span class="keywordflow">if</span>( ctx )</div>
<div class="line">  {</div>
<div class="line">    <a class="code hl_class" href="classas_i_script_engine.html">asIScriptEngine</a>* engine = ctx-&gt;<a class="code hl_function" href="classas_i_script_context.html#a540b3857746082a17740fa6e0757d7b1">GetEngine</a>();</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// The script array needs to know its type to properly handle the elements.</span></div>
<div class="line">    <span class="comment">// Note that the object type should be cached to avoid performance issues</span></div>
<div class="line">    <span class="comment">// if the function is called frequently.</span></div>
<div class="line">    <a class="code hl_class" href="classas_i_type_info.html">asITypeInfo</a>* t = engine-&gt;<a class="code hl_function" href="classas_i_script_engine.html#a0f010c8443fa7e1333021e7cbf7c8d0f">GetTypeInfoByDecl</a>(<span class="stringliteral">&quot;array&lt;string&gt;&quot;</span>);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// Create an array with the initial size of 3 elements</span></div>
<div class="line">    CScriptArray* arr = CScriptArray::Create(t, 3);</div>
<div class="line">    <span class="keywordflow">for</span>( <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> i = 0; i &lt; arr-&gt;GetSize(); i++ )</div>
<div class="line">    {</div>
<div class="line">      <span class="comment">// Set the value of each element</span></div>
<div class="line">      <span class="keywordtype">string</span> val(<span class="stringliteral">&quot;test&quot;</span>);</div>
<div class="line">      arr-&gt;SetValue(i, &amp;val);</div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// The ref count for the returned handle was already set in the array&#39;s constructor</span></div>
<div class="line">    <span class="keywordflow">return</span> arr;</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="ttc" id="aclassas_i_script_context_html"><div class="ttname"><a href="classas_i_script_context.html">asIScriptContext</a></div><div class="ttdoc">The interface to the virtual machine.</div><div class="ttdef"><b>Definition:</b> angelscript.h:2735</div></div>
<div class="ttc" id="aclassas_i_script_context_html_a540b3857746082a17740fa6e0757d7b1"><div class="ttname"><a href="classas_i_script_context.html#a540b3857746082a17740fa6e0757d7b1">asIScriptContext::GetEngine</a></div><div class="ttdeci">virtual asIScriptEngine * GetEngine() const =0</div><div class="ttdoc">Returns a pointer to the engine.</div></div>
<div class="ttc" id="aclassas_i_script_engine_html"><div class="ttname"><a href="classas_i_script_engine.html">asIScriptEngine</a></div><div class="ttdoc">The engine interface.</div><div class="ttdef"><b>Definition:</b> angelscript.h:1102</div></div>
<div class="ttc" id="aclassas_i_script_engine_html_a0f010c8443fa7e1333021e7cbf7c8d0f"><div class="ttname"><a href="classas_i_script_engine.html#a0f010c8443fa7e1333021e7cbf7c8d0f">asIScriptEngine::GetTypeInfoByDecl</a></div><div class="ttdeci">virtual asITypeInfo * GetTypeInfoByDecl(const char *decl) const =0</div><div class="ttdoc">Returns a type by declaration.</div></div>
<div class="ttc" id="agroup__api__principal__functions_html_gaf8b78824db10b0f757990805a4e18f70"><div class="ttname"><a href="group__api__principal__functions.html#gaf8b78824db10b0f757990805a4e18f70">asGetActiveContext</a></div><div class="ttdeci">AS_API asIScriptContext * asGetActiveContext()</div><div class="ttdoc">Returns the currently active context.</div></div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Sun May 21 2023 10:12:39 for AngelScript by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6 </li>
  </ul>
</div>
</body>
</html>
